﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using TaoSH.AppCode;
using TaoSH.Data;

namespace TaoSH
{
    public partial class UploadFileForm : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Response.ContentType = "text/plain";
                Response.Charset = "utf-8";
                string strUploadPath = Request.PhysicalApplicationPath + "Upload\\";
                string strFileID = "";
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    HttpPostedFile postedFile = Request.Files[i];
                    string fileName = strUploadPath + Path.GetFileName(postedFile.FileName);
                    if (fileName != "")
                    {
                        JH_Auth_FormAttchg attch = new JH_Auth_FormAttchg();
                        attch.FileNewName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + fileName.Substring(fileName.LastIndexOf("."));
                        attch.FileOldName = postedFile.FileName;
                        attch.FileSize = postedFile.ContentLength.ToString();
                        attch.iseffective = "N";
                        attch.Crdate = DateTime.Now;
                        attch.Cruser = UserInfo.User.UserName;
                        new JH_Auth_FormAttchgB().Insert(attch);
                        strFileID = attch.id.ToString();
                        postedFile.SaveAs(strUploadPath + attch.FileNewName);

                    }
                }
                Response.Write(strFileID);
            }
            catch (Exception ex)
            {
                Response.ContentType = "text/plain";
                Response.Write(ex.Message);
            }
            finally
            {
                Response.Flush();
                Response.End();
            }
        }
    }
}